home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995…tember: Reference Library / Dev.CD Sep 95 RL / Dev.CD Sep 95 RL.toast / mac / Technical Documentation / develop / develop Issue 15 code / Floating Windows / Floating Windows Code / Shell Code / menuDispatch.c < prev    next >
Encoding:
Text File  |  1995-07-18  |  4.5 KB  |  201 lines  |  [TEXT/MMCC]

  1. // If the interfaces aren't included yet, do the standard includes. Otherwise, precompiled headers
  2. // have been loaded already, thank you very much
  3. #ifndef __TYPES__
  4.     #include <Types.h>
  5.     #include <AppleEvents.h>
  6.     #include <Desk.h>
  7.     #include <Dialogs.h>
  8.     #include <Editions.h>
  9.     #include <Events.h>
  10.     #include <Menus.h>
  11.     #include <SegLoad.h>
  12.     #include <TextUtils.h>
  13.     #include <ToolUtils.h>
  14.     #include <Windows.h>
  15. #endif
  16.  
  17. #include "eventHandler.h"
  18. #include "fileMenuRoutines.h"
  19. #include "menuDispatch.h"
  20. #include "WindowExtensions.h"
  21.  
  22. /* Globals */
  23.     
  24. extern Boolean                gDone;                        // Set to true if user selects Quit
  25. extern WindowRef            gRecordingFloater;            // Reference to recording floating window
  26. extern WindowRef            gToolsFloater;                // Reference to tools floating window
  27. extern ActivateHandlerUPP    gActivateEventHandler;
  28.  
  29. // a test routine
  30. void TestManualModal(void);
  31.  
  32.  
  33. void DoMenuCommand(long menuChoice)
  34. {
  35.     long    menuID;
  36.     long    menuItem;
  37.     short    daRef;
  38.     Str255    daName;
  39.     Boolean    editResult;
  40.     
  41.     menuID = (menuChoice & 0xFFFF0000) >> 16;
  42.     menuItem = menuChoice & 0x0000FFFF;
  43.     
  44.     switch (menuID) {
  45.         case rAppleMenuID:        if (menuItem == kAboutItem)
  46.                                     DoAbout();
  47.                                 else {
  48.                                     GetItem(GetMHandle(rAppleMenuID), (short) menuItem, daName);
  49.                                     daRef = OpenDeskAcc(daName);
  50.                                 }
  51.                                 break;
  52.         case rFileMenuID:        HandleFileMenuItems((short) menuItem);
  53.                                 break;
  54.         case rEditMenuID:        editResult = SystemEdit((short) (menuItem - 1));
  55.                                 break;
  56.         case rFloatersMenuID:    HandlerFloaterMenuItems((short) menuItem);
  57.                                 break;
  58.         
  59.         // for testing...
  60.         case 132:                TestManualModal();
  61.                                 break;
  62.     }
  63.     HiliteMenu(0);
  64. }
  65.  
  66. void DoAbout()
  67. {
  68.     short    alertResult;
  69.     
  70.     DeactivateFloatersAndFirstDocumentWindow();
  71.     alertResult = Alert(256, nil);
  72.     ActivateFloatersAndFirstDocumentWindow();
  73. }
  74.  
  75. void HandleFileMenuItems(short theItem)
  76. {
  77.     switch (theItem) {
  78.         case kNewItem:        CreateNewDocumentWindow();
  79.                             break;
  80.         case kOpenItem:        GetFileToOpen();
  81.                             break;
  82.         case kCloseItem:    CloseFirstDocumentWindow();
  83.                             break;
  84.         case kFindItem:        ShowFindDialog();
  85.                             break;
  86.         case kQuitItem:        gDone = true;
  87.                             break;
  88.     }
  89. }
  90.  
  91. void HandlerFloaterMenuItems(short theItem)
  92. {
  93.     Boolean        floaterVisible;
  94.     WindowRef    floaterPicked;
  95.     
  96.     switch (theItem) {
  97.         case kRecordingItem:    floaterPicked = gRecordingFloater;
  98.                                 break;
  99.         case kToolsItem:        floaterPicked = gToolsFloater;
  100.                                 break;
  101.     }
  102.     
  103.     floaterVisible = IsWindowVisible(floaterPicked);
  104.     if (floaterVisible == false)
  105.         ShowReferencedWindow(floaterPicked);
  106.     else
  107.         HideReferencedWindow(floaterPicked);
  108.     CheckItem(GetMHandle(rFloatersMenuID), theItem, !floaterVisible);
  109. }
  110.  
  111. void CreateNewDocumentWindow()
  112. {
  113.     WindowRef    newDocumentWindow;
  114.     OSErr        createWindowError;
  115.     
  116.     ValidateWindowList();
  117.     createWindowError = GetNewWindowReference(&newDocumentWindow, 128,
  118.                                                 (WindowRef) -1, gActivateEventHandler);
  119.     if (createWindowError == noErr) {
  120.         ShowReferencedWindow(newDocumentWindow);
  121.         EnableItem(GetMHandle(rFileMenuID), kCloseItem);
  122.     }
  123. }
  124.  
  125. void CloseFirstDocumentWindow()
  126. {
  127.     WindowRef    firstDocumentWindow;
  128.     
  129.     ValidateWindowList();
  130.     firstDocumentWindow = FrontNonFloatingWindow();
  131.     if (firstDocumentWindow != nil)
  132.         DisposeWindowReference(firstDocumentWindow);
  133.     if (FrontNonFloatingWindow() == nil)
  134.         DisableItem(GetMHandle(rFileMenuID), kCloseItem);
  135. }
  136.  
  137. void ShowFindDialog()
  138. {
  139.     DialogRef    findDialog;
  140.     
  141.     DeactivateFloatersAndFirstDocumentWindow();
  142.     findDialog = GetNewDialog(257, nil,  (WindowRef)-1);
  143.     DisableItem(GetMHandle(rAppleMenuID), 0);
  144.     DisableItem(GetMHandle(rFileMenuID), 0);
  145.     DrawMenuBar();
  146. }
  147.  
  148. void DisposeFindDialog()
  149. {
  150.     DialogRef    findDialog;
  151.     
  152.     findDialog = (DialogRef)FrontWindow();
  153.     DisposeDialog(findDialog);
  154.     ActivateFloatersAndFirstDocumentWindow();
  155.     EnableItem(GetMHandle(rAppleMenuID), 0);
  156.     EnableItem(GetMHandle(rFileMenuID), 0);
  157.     DrawMenuBar();
  158. }
  159.  
  160. void TestManualModal(void)
  161. {
  162.     Rect        theRect;
  163.     OSErr        error;
  164.     WindowAttributes    attributes;
  165.     WindowRef    wind;
  166.     ControlHandle    cHandle;
  167.  
  168.     // Put up a movable modal
  169.     attributes = kHasModalBorderMask + kHasDocumentTitlebarMask;
  170.     SetRect(&theRect, 200, 100, 400, 250);
  171.     
  172.     // create the window invisibly
  173.     error = NewWindowReference(&wind, &theRect, "\pTesty Mambo", false,
  174.                     attributes, (WindowRef) -1, (long)'DAVE', nil);
  175.     
  176.     if(wind == nil)
  177.         return;
  178.         
  179.     // Set its kind
  180.     //SetWindowKind(wind, dialogKind);
  181.     
  182.     // Add a button
  183.     SetRect(&theRect, 20, 20, 80, 40);
  184.     cHandle = NewControl(wind, &theRect, "\pPress", true, 0, 0, 1, 0, 'DAVE');
  185.     
  186.     // Show window
  187.     DeactivateFloatersAndFirstDocumentWindow();
  188.     ShowReferencedWindow(wind);
  189. }
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.